import {
  combineReducers,
  legacy_createStore as createstore,
  applyMiddleware,
} from "redux";
import thunk from "redux-thunk";
import { composeWithDevTools } from "redux-devtools-extension";
import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";
import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2";

import global from "./reducers/global";
import home from "./reducers/home";

const persistConfig = {
  key: "root",
  storage: storage,
  stateReconciler: autoMergeLevel2, // 查看 'Merge Process' 部分的具体情况
};
const reducers: any = combineReducers({ global, home });
const persistedReducer: any = persistReducer(persistConfig, reducers);
export const store = createstore(
  persistReducer(persistConfig, persistedReducer),
  composeWithDevTools(applyMiddleware(thunk))
);
//仅仅只是为了typescript
const fortypestore = createstore(
  combineReducers({ global, home }),
  composeWithDevTools(applyMiddleware(thunk))
);
export type rootState = ReturnType<typeof fortypestore.getState>;
export default persistStore(store);
